<template>
  <div class="box">
    <el-form
      :model="ruleForm"
      :inline="false"
      ref="ruleForm"
      label-width="200px"
      class="demo-ruleForm"
      size="medium"
      :rules="rules"
    >
      <!-- 补发变更/转让/续展证明申请 -->
      <div class="must">
        <!-- <el-form-item label="申请人名称：" prop="applyName">
          <el-input v-model="ruleForm.applyName" placeholder="请填写申请人名称"></el-input>
           <div class="inform">
                <img src="../../assets/imgs/inform.png" alt="通知" />
                <div class="content">
                  <span>示例：北京市xxx网络科技有限公司/张三</span>
                </div>
            </div>
        </el-form-item>
        <el-form-item label="申请人地址：" prop="applyAddr">
          <el-input v-model="ruleForm.applyAddr" placeholder="请填写申请人地址"></el-input>
          <div class="inform">
                <img src="../../assets/imgs/inform.png" alt="通知" />
                <div class="content">
                  <span>示例：北京市xx区xx街xx号</span>
                </div>
          </div>
        </el-form-item>
        <el-form-item label="联系人：" prop="linkman">
          <el-input v-model="ruleForm.linkman" placeholder="请填写联系人"></el-input>
          <div class="inform">
                <img src="../../assets/imgs/inform.png" alt="通知" />
                <div class="content">
                  <span>示例：北京市xxx网络科技有限公司/张三</span>
                </div>
          </div>
        </el-form-item>
        <el-form-item label="代理机构名称：" prop="institution">
          <el-input v-model="ruleForm.institution" placeholder="请填写代理机构名称"></el-input>
          <div class="inform">
                <img src="../../assets/imgs/inform.png" alt="通知" />
                <div class="content">
                  <span>示例：北京市xxx网络科技有限公司</span>
                </div>
          </div>
        </el-form-item> -->
        <el-form-item label="商标注册号：" prop="number">
          <el-input v-model="ruleForm.number" placeholder="请填写商标注册号"></el-input>
        </el-form-item>
        <el-form-item label="补发证明事项：" prop="reissue">
          <span id="star">*</span>
          <el-radio-group v-model="ruleForm.radio" @change="eliminate">
            <el-radio :label="0">变更证明</el-radio>
            <el-radio :label="1">转让证明</el-radio>
            <el-radio :label="2">续展证明</el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- v-if隐藏输入内容 -->
        <el-form-item label="变更前注册名义（地址）：" prop="oldsite" v-show="ruleForm.radio == 0?true:false" v-if="ruleForm.radio == 0">
          <el-input v-model="ruleForm.oldsite" placeholder="请填写变更前注册名义（地址）"></el-input>
          <div class="inform">
                <img src="../../assets/imgs/inform.png" alt="通知" />
                <div class="content">
                  <span>示例：北京市xx区xx街xx号</span>
                </div>
          </div>
        </el-form-item>


        <el-form-item label="变更后注册名义（地址）：" prop="newsite" v-show="ruleForm.radio == 0?true:false" v-if="ruleForm.radio == 0">
          <el-input v-model="ruleForm.newsite" placeholder="请填写变更后注册名义（地址）"></el-input>
        </el-form-item>
        <el-form-item label="转让人名称：" prop="oldname" v-show="ruleForm.radio == 1?true:false" v-if="ruleForm.radio == 1">
          <el-input v-model="ruleForm.oldname" placeholder="请填写转让人名称"></el-input>
          <div class="inform">
                <img src="../../assets/imgs/inform.png" alt="通知" />
                <div class="content">
                  <span>示例：北京市xxx网络科技有限公司/张三</span>
                </div>
            </div>
        </el-form-item>
        <el-form-item label="受让人名称：" prop="newname" v-show="ruleForm.radio == 1?true:false" v-if="ruleForm.radio == 1">
          <el-input v-model="ruleForm.newname" placeholder="请填写受让人名称"></el-input>
        </el-form-item>
        <el-form-item label="商标续展注册有效期：" prop="time" v-show="ruleForm.radio == 2?true:false" v-if="ruleForm.radio == 2">
           <el-date-picker v-model="ruleForm.time" type="daterange" align="right" unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
    </el-date-picker>
          <!-- <el-input v-model="ruleForm.time" placeholder="请填写商标续展注册有效期"></el-input> -->
          <!-- <el-date-picker v-model="ruleForm.time" type="date" placeholder="请填写商标续展注册有效期">
    </el-date-picker> -->
          <div class="inform">
                <img src="../../assets/imgs/inform.png" alt="通知" />
                <div class="content">
                  <span>示例：2020-03-14 -- 2020-04-05</span>
                </div>
          </div>
        </el-form-item>

        <el-form-item class="upload" label="网上确认书：" prop="afterAmount">
          <span id="newstar">*</span>
          <upfile :callback="setSure">
            <div class="img-box" v-if="showImg">
              <imgshow><img :src="ruleForm.imgAddr" alt=""></imgshow>
            </div>
          </upfile>
          <div class="exam-img">
              <div class="img-inform">

                  <img src="../../assets/imgs/inform.png">
                  <span>示例:</span>
              </div>
              <examimg :imgType="4"></examimg>
          </div>
          <div>
            <span class="informs">
              请点此
              <a :href="mconfig.host + '/file/download?fileType=2'"
                >下载商标说明书</a
              >,查到相应商标编号并填充
            </span>
            <br />
            <span class="notice"
              >请将下载的网上确认书填写完成, 然后上传JPG文件或是PNG文件</span
            >
          </div>
        </el-form-item>

        <el-form-item label="其他附件：" prop="dengjichenluofile">
          <uploads :callback="backUrl" :delUrl="delUrl" :file_config="{field:'dengjichenluofile'}" :list="ruleForm.dengjichenluofile"></uploads>
          <div class="inform">
            <img src="../../assets/imgs/inform.png" alt="通知" />
            <div class="content">
              <span>提示：其他附件</span>
            </div>
          </div>
        </el-form-item>

        <el-form-item>
          <div class="btns">
            <el-button type="primary" @click="outStep">上一步</el-button>
            <el-button type="primary" @click="submitCheck('ruleForm')">提交并审核</el-button>
          </div>
        </el-form-item>
        <el-dialog
          class="dialog"
          :show-close="false"
          :center="true"
          :visible.sync="dialogVisible"
          width="460px"
        >
        <!-- :before-close="handleClose" -->
          <div class="hint">
           <img src="../../assets/imgs/branch.png" alt="提示图片" />
            <span>选择您想去办理的网点</span>
          </div>
          <el-form-item label="选择网点：" prop="value" >
            <el-select v-model="ruleForm.value" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.deptId"
                :label="item.deptName"
                :value="item.deptId"
              >
                <span style="float: left">{{ item.deptName }}</span>
                <span style="float: right; color: #8492a6; font-size: 13px">{{ item.address }}</span>
              </el-option>
            </el-select>
          </el-form-item>
          <div slot="footer" class="dialog-footer">
            <el-button type="info" @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="submitForm('ruleForm')">确 定</el-button>
          </div>
        </el-dialog>
        <el-dialog
          class="hintMsg"
          :show-close="false"
          title="温馨提示"
          :visible.sync="centerDialogVisible"
          width="462px"
        >
          <span>您的信息已提交，工作人员将在3-5日内对你的信息审核，审核通过后即可预约业务，审核结果将通过短信的方式发送给你。</span>
          <span slot="footer" class="dialog-footer">
            <el-button type="primary" @click="skip">确 定</el-button>
          </span>
        </el-dialog>
      </div>
    </el-form>
  </div>
</template>
<script>
import BaseUpload from "./BaseUpload";
import upfile from "../common/upfile.vue"
import imgshow from '../common/imgshow'
import examimg from "../common/imgExample";
import uploads from "../common/uploads";
export default {
  data() {
    return {
      yearzs:[],
      datezs:[],
      datez:"",
      yearz:"",
      //网点列表
      options: [],
      //提交成功弹出框变量
      centerDialogVisible: false,
      //网点弹出框控制变量
      dialogVisible: false,

      // add:0,
      //表单唯一id
      classId: "",
      // 是否显示图片
      showImg: false,
      // 是否上传图片
      uploadImg: false,
      // 是否必填
      mustInput:true,

      //填写的信息
      ruleForm: {
        // applyName:"",
        // applyAddr:"",
        // linkman: "",
        // institution: "",
        // upload:"",
        reissue:"",
        number: "",
        radio: 0,
        radios: 0,
        oldsite: "",
        newsite: "",
        oldname: "",
        newname: "",
        dengjichenluofile:[],
        time: "",
        value: "",
        imgAddr:"",
      },
      branchNetworkId: "",
      rules:{
        // 申请人
        // applyName:[
        //   { required: true, message: "选项不能为空", trigger: "change" },
        //   {
        //     pattern: /^[\u0391-\uFFE5A-Za-z]+$/,
        //     message: "请输入正确的名称",
        //     trigger: "blur",
        //   },
        // ],
        // 申请地址
        // applyAddr:[
        //   { required: true, message: "选项不能为空", trigger: "change" },
        //   {
        //     pattern: /^((省|自治区).+(市))|(市|行政区|自治州).+(区|县).+(路|街|道|村).*$/,
        //     message: "你的地址格式不正确",
        //     trigger: "blur",
        //   },
        // ],
        // linkman:[
        //   { required: true, message: "选项不能为空", trigger: "change" },
        //   {
        //     pattern: /^[\u0391-\uFFE5A-Za-z]+$/,
        //     message: "请输入正确的名称",
        //     trigger: "blur",
        //   },
        // ],
        number:[
          {
              required: true,
              message: "请输入商标注册号",
              trigger: "blur",
          },
          {
              pattern: /^[A-Za-z0-9]{0,30}$/,
              message: "请输入正确的商标注册号",
              trigger: "blur",
          },
        ],
        // dengjichenluofile: [
        //   { required: true, message: "附件不能为空", trigger: "change" },
        // ],
        oldsite:[
          { required: true, message: "选项不能为空", trigger: "change" },
            // {
            //   pattern: /^((省|自治区).+(市))|(市|行政区|自治州).+(区|县).+(路|街|道|村).*$/,
            //   message: "你的地址格式不正确",
            //   trigger: "blur",
            // },
            ],
        newsite:[
          { required: true, message: "选项不能为空", trigger: "change" },
            // {
            //   pattern: /^((省|自治区).+(市))|(市|行政区|自治州).+(区|县).+(路|街|道|村).*$/,
            //   message: "你的地址格式不正确",
            //   trigger: "blur",
            // },
            ],
        newname:[
          { required: true, message: "选项不能为空", trigger: "change" },
          {
            pattern: /^[\u0391-\uFFE5A-Za-z]+$/,
            message: "请输入正确的中文名称",
            trigger: "blur",
          },
        ],
        oldname:[
          { required: true, message: "选项不能为空", trigger: "change" },
          {
            pattern: /^[\u0391-\uFFE5A-Za-z]+$/,
            message: "请输入正确的中文名称",
            trigger: "blur",
          },
        ],
        time:[
          { required: true, message: "选项不能为空", trigger: "change" },
          // {
          //   pattern: /^\d{4}-\d{2}-\d{2}$/,
          //   message: "请输入正确的日期",
          //   trigger: "blur",
          // },
        ],
        // upload:[
        //   { required: true, message: "商标确认书不能为空", trigger: "blur" },
        // ],
        // reissue:[
        //   { required: true, message: "选项不能为空", trigger: "change" },
        // ],
        // institution:[
        //   { required: true, message: "选项不能为空", trigger: "change" },
        //   {
        //     pattern: /^[\u0391-\uFFE5A-Za-z]+$/,
        //     message: "请输入正确的机构名称",
        //     trigger: "blur",
        //   },
        // ]
      },
    };
  },
  mounted() {
    //获取从存储在路由中的classId
    this.classId = this.$route.query.id;
    //获取网点列表
    this.$http.get("/trademark/system/dept/findDept").then((res) => {
      this.options = res.data.data;
    });

    // console.log(this.$store.state.alterData.data);
    if(this.$store.state.stateJdg){
      this.showImg = true
      this.uploadImg = true
      let {
        applicant,
        appliAddr,
        contacts,
        agent,
        registNum,
        remark,
        otherfile,
        beforeRegistChange,
        afterRegistChange,
        transferorName,
        transfereesName,
        registValidity,
      } = this.$store.state.alterData.data;


      let s = registValidity.split(",")
      for(let i = 0;i < s.length;i++){
        this.datez = new Date(s[i]);
        this.yearz = this.datez.getFullYear() + '-' + (this.datez.getMonth()+1) + '-' + this.datez.getDate();
        this.datezs.push(this.yearz)
      }

      // this.ruleForm.applyName = applicant;
      // this.ruleForm.applyAddr = appliAddr;
      // this.ruleForm.linkman = contacts;
      // this.ruleForm.institution = agent;
      this.ruleForm.number = registNum;
      this.ruleForm["dengjichenluofile"] = JSON.parse(otherfile);
      this.ruleForm.radio = remark;
      this.ruleForm.oldsite = beforeRegistChange;
      this.ruleForm.newsite = afterRegistChange;
      this.ruleForm.oldname = transferorName;
      this.ruleForm.newname = transfereesName;
      this.yearzs = this.datezs;
      // .split(",")
      this.ruleForm.time = this.yearzs
      this.ruleForm.imgAddr = this.mconfig.host + this.$store.state.alterData.public.qrfile
    }
  },

  methods: {
    // 时间清空
    // timez(){
    //   this.yearzs = ""
    // },
    //选择框切换清除数据
    eliminate(){
      if(this.ruleForm.radio == 0){
        this.ruleForm.oldname = ""
        this.ruleForm.newname = ""
        this.ruleForm.time = ""
      }
      if(this.ruleForm.radio == 1){
        this.ruleForm.oldsite = ""
        this.ruleForm.newsite = ""
        this.ruleForm.time = ""
      }
      if(this.ruleForm.radio == 2){
        this.ruleForm.oldname = ""
        this.ruleForm.newname = ""
        this.ruleForm.oldsite = ""
        this.ruleForm.newsite = ""
      }
    },
    backUrl(url,file_config){
        this.ruleForm[file_config["field"]].push(url)
    },
    delUrl(index,file_config){
        this.ruleForm[file_config["field"]].splice(index,1)
        this.$set(this.ruleForm,file_config["field"],this.ruleForm[file_config["field"]])
    },
    // 提交并审核验证
    submitCheck(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid && this.uploadImg == true) {
          this.dialogVisible = true;
        } else if (!valid) {
          this.open1("存在错误的格式填写", "error");
        } else {
          this.open1("请上传网上确认书", "error");
        }
      });
      this.yearzs = []
    },
    setSure(files){
      this.ruleForm.qrfile=files[0]
      this.showImg = false

       if (this.ruleForm.qrfile) {
         this.uploadImg = true;
      }else {
         this.uploadImg = false;
      }

    },
    //返回上一步
    outStep() {
      this.$emit("wp", 1, "请填写申请业务信息");
    },
    //提示模板
    open1(msg, types = "success") {
      this.$message({
        message: msg,
        type: types,
      });
    },
    //弹出框的选项确认框
    // handleClose(done) {
    //   this.$confirm("确认关闭？")
    //     .then((_) => {
    //       done();
    //     })
    //     .catch((_) => {});
    // },
    //表单提交事件
    submitForm(formName) {
      let _this = this;
        if (this.ruleForm.value != "") {
          //每次提交重新生成新的FormData用于储存新的数据
          var formData = new FormData();
          this.dialogVisible = false;
          let arr=this.$store.getters.getRuleForm
          for(let key in arr){
            formData.append(key,arr[key])
          }
          for(let i = 0;i < this.ruleForm.time.length;i++){
          // this.datez = new Date(this.ruleForm.time[i]);
          // this.yearz = this.datez.getFullYear() + '-' + this.datez.getMonth() + '-' + this.datez.getDate();
          this.yearzs.push(this.ruleForm.time[i])
          }
          console.log(this.yearzs)


          //我的
          // formData.append("classId", this.$route.query.id);
          formData.append("classId", this.classId);
          formData.append("branchNetworkId", this.ruleForm.value);
          formData.append("applicant", this.ruleForm.applyName);
          formData.append("appliAddr", this.ruleForm.applyAddr);
          formData.append("contacts", this.ruleForm.linkman);
          formData.append("agent", this.ruleForm.institution);
          formData.append("registNum", this.ruleForm.number);
          formData.append("remark", this.ruleForm.radio);
          formData.append("beforeRegistChange", this.ruleForm.oldsite);
          formData.append("afterRegistChange", this.ruleForm.newsite);
          formData.append("transferorName", this.ruleForm.oldname);
          formData.append("transfereesName", this.ruleForm.newname);
          formData.append("registValidity", this.yearzs);
          formData.append("otherfile", JSON.stringify(this.ruleForm.dengjichenluofile)); //其他出质人

          if(this.showImg){
            formData.append("qrfiles", {}); // 如果没有修改, 则使用之前的qrfile
            console.log(this.$store.state.alterData.public.qrfile);
          }else{
            formData.append("qrfiles", this.ruleForm.qrfile); // 网上确认书
          }

          if(this.$store.state.stateJdg){
            formData.append("modelId", this.$store.state.alterData.public.modelId)
          }
          formData.append("proAppends","")

          let x = this.$store.state.storeId
          formData.append("id", x);
          //配置请求头
          var config = {
            header: {
              "Content-Type": "multipart/form-data",
            },
          };
          // axios向后端发送数据
          this.$http
            .post(this.$store.state.stateJdg?"/trademark/proafo/modifyNoCommit":"/trademark/proafo/firstSubmit", formData, config)
            .then(function (response) {
              //若状态码不为200则不跳转
              ////console.log(response);
              if (response.data.code != 200) {
                _this.open1("提交失败", "error");
                return;
              }
              _this.centerDialogVisible = true;
            })
            .catch(function (error) {});
        } else {
          this.open1("请选择网点编号", "error")
          return false;
        }
    },
    //跳转函数
    skip() {
      this.centerDialogVisible = false;
      this.open1("操作成功");
      this.$router.push({
        path: "/business/myBusiness/auditing",
      });
    },
    //重置表单函数(没用上)
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
  components: {
    BaseUpload,upfile,imgshow,examimg,uploads
  },
};
</script>
<style lang="less" scoped>
.fzk-style{
  border: 1px black solid;
  height: 20px;
  width: 30px;
}
.btns {
  display: flex;
  justify-content: center;
  .el-button {
    margin: 0 20px;
  }
}
.box {
  display: flex;
  flex-direction: column;
  align-items: center;
  // margin-top: 100px;
  width: 100%;
  min-height: 800px;
  .tle {
    font-size: 24px;
    color: #000;
  }
  .el-form{
    .el-input{
      width: 80%;
    }
  }
  .must,
  .select {
    display: flex;
    position: relative;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px 0 30px;
    margin-bottom: 80px;
    // width: 1000px;
    // border: 1px solid #bbbbbb;
    border-radius: 10px;
    .el-form-item {
      width: 680px;
      // 输入框长度改为80%
    }
    .inline {
      display: flex;
      .el-form-item {
        margin: 0;
        width: 290px !important;
      }
    }
  }
  .must {
    margin-bottom: 20px;
  }
  .line {
    width: calc(100% - 280px);
    margin: 10px auto;
    height: 1px;
    border-top: 1px dashed #d9d9d9;
  }
  .imgHint {
    margin: 5px;
    font-size: 12px;
    line-height: 17px;
    color: #f5222d;
  }
  .affirm {
    font-size: 12px;
    color: #a0a3a5;
    a {
      text-decoration: none;
      color: #3685ff;
    }
  }
  .input {
    width: 190px;
  }
  .upload {
    margin: 20px 0;
  }
  .type-number {
    width: 250px;
  }
  .inform {
    display: flex;
    align-items: center;
    position: absolute;
    top: 0;
    left: 80%;
    width: 300px;
    height: 32px;
    color: #F96900;
    font-size: 10px;
    line-height: 14px;
    img {
      margin: 11px;
    }
    .content {
      display: flex;
      flex-direction: column;
      .ts {
        text-indent: 3em;
      }
    }
  }
  .informs {
    position: absolute;
    width: 500px;
    font-size: 12px;
    color: #a0a3a5;
    a {
      text-decoration: none;
      color: #3685ff;
    }
  }
  .notice {
    color: #f00;
    font-size: 12px;
  }
  .tle {
    list-style: none;
    margin: 40px 0 20px;
    font-size: 24px;
    & ~ .tle {
      color: #bbb;
    }
  }
  .hint {
    color: #F96900;
    background-color: #fff;
    .el-form-item__label {
      width: 150px;
    }
    img {
      width: 20px;
    }
  }
  .el-steps {
    width: 70%;
    height: 200px;
  }
  .el-button {
    //display: block;
    display: inline;
    margin: 0 20px;
    // background-color: #67c23a !important;
    // border-color: #67c23a !important;
  }

  .common .el-button {
    background-color: #fff !important;
    border-color: #bbb !important;
  }
}
.dialog-footer {
  display: flex;
  justify-content: space-between;
  color: #fff;
  .lan {
    background-color: #2c9dfc !important;
    border-color: #2c9dfc !important;
  }
}

.dialog /deep/.el-form-item__label {
  width: 100px !important;
}
.dialog /deep/.el-form-item__content {
  margin-left: 100px !important;
  display: flex;
  justify-content: left;
}
.dialog /deep/.el-input {
  width: 250px;
}
.el-checkbox-group {
  line-height: 14px;
}
// .is-checked/deep/.el-radio__inner,
.is-checked/deep/.el-checkbox__inner {
  border-color: #999999;
  background: #999999;
}
// .el-radio/deep/.el-radio__inner:hover {
//   border-color: #999999 !important;
// }
.is-checked/deep/.el-radio__label,
.is-checked/deep/.el-checkbox__label {
  color: #333;
}
.is-focus .el-checkbox__inner {
  border-color: #999999 !important;
}
.el-checkbox/deep/.el-checkbox__inner:hover {
  border-color: #999999 !important;
}
.el-step__head.is-process {
  border-color: #f96900;
  color: #f96900 !important;
}
.hintMsg {
  /deep/.el-dialog__header {
    display: flex;
    justify-content: center;
    font-weight: bold;
  }
  .dialog-footer {
    justify-content: center;
    .el-button {
      border-color: #2c9dfc !important;
      background: #2c9dfc !important;
    }
  }
}


//fiexed dialog 0902

/deep/ .el-dialog.el-dialog--center /deep/ {
    .el-dialog__header {
        padding: 0;
    }

    .el-dialog__body {
        padding: 20px;
    }

    .hint {
        color: #F96900;
        background-color: #fff;
        padding: 0;
        padding-bottom: 20px;
    }

    .el-button {
        margin: 0;
    }

    .el-form-item__label {
        width: 86px !important;
    }
}
#star{
  position: absolute;
  color: red;
  margin-left: -120px;
}
#newstar{
  position: absolute;
  color: red;
  margin-left: -105px;
}
.exam-img{
  position: absolute;
  top: 0;
  left: 465px;
}
.img-inform{
  img{
    position: absolute;
    top: 50%;
    left: 50%;
    margin-left: -140px;
    transform: translate(-50%,-50%);
  }
  span{
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%,-50%);
      white-space: nowrap;
      margin-left: -100px;
      width: 50px;
      color: #f96900;
  }
}
</style>
